/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package frame;

import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTable;
import javax.swing.event.ListSelectionEvent;
import kbcquiz.App;

import javax.swing.ScrollPaneConstants;
import javax.swing.event.ListSelectionListener;
import library.DB;
import library.Debug;
import library.PagingModel;
import library.QuestionRecord;
import library.UserRecord;
import library.Utils;

public class Admin extends javax.swing.JFrame {

    PagingModel pm, am;
    String[] header = new String[]{"Question ID", "Category ID", "Category Name", "Content"};
    String[] userheader = new String[]{"User ID", "User Name"};
    
    public Admin() {
        pm = new PagingModel(header, new QuestionRecord());
        am = new PagingModel(userheader, new UserRecord());

        tblManager = new javax.swing.JTable(pm);
        tblManager.setDragEnabled(false);

        tblAdmin = new JTable(am);
        
        initComponents();
        btnRemove.setEnabled(false);
        btnPrevious.setEnabled(false);
        btnPreviousAdmin.setEnabled(false);
        btnNext.setEnabled(pm.getPageCount() > 1);
        lbAdminPage.setText("Page: " + (am.getPageOffset() + 1) + "/" + am.getPageCount());
        lbManagerPage.setText("Page: " + (pm.getPageOffset() + 1) + "/" + pm.getPageCount());
        tblManager.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                int qid = 0;
                try {
                    qid = Integer.parseInt(pm.getValueAt(tblManager.getSelectedRow(), 0).toString());
                }
                catch (Exception ex) {
                }

                btnRemove.setEnabled(qid > 0);
            }
        });
        tblManager.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    if (tblManager.getSelectedRow() >= 0) {
                        int qid = Integer.parseInt(pm.getValueAt(tblManager.getSelectedRow(), 0).toString());
                        ResultSet rs = DB.execQuery("SELECT * FROM Questions AS q INNER JOIN Categories AS c ON c.CatID = q.CatID INNER JOIN Answers AS a ON q.QuestionID = a.QuestionID WHERE q.QuestionID = " + qid + " ORDER BY a.AnswerID");
                        String Question = null;
                        int correct = 0, catid = 0, QuestionID = 0;
                        String[] Answers = new String[4];
                        int[] AnswersID = new int[4];
                        try {
                            int i = 0;
                            while (rs.next()) {
                                if (QuestionID <= 0) {
                                    QuestionID = rs.getInt("QuestionID");
                                }
                                if (Question == null) {
                                    Question = rs.getString("Name");
                                }
                                Answers[i] = rs.getString("Contents");
                                if (rs.getBoolean("IsCorrect")) {
                                    correct = i;
                                }
                                AnswersID[i] = rs.getInt("AnswerID");
                                i++;
                                catid = rs.getInt("CatID");
                            }
                            rs.close();
                            AdminNewQA qa = App.getAdminNewQA().resetData().loadData(QuestionID, Question, Answers, correct, catid, AnswersID);
                            qa.setQAEditMode(true);
                            App.setDisplay(qa);
                        }
                        catch (SQLException ex) {
                            Logger.getLogger(Admin.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                    else {
                        Utils.Alert("Please select data first");
                    }
                }
            }
        });

        tblAdmin.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                int aid = 0;
                try {
                    aid = Integer.parseInt(am.getValueAt(tblAdmin.getSelectedRow(), 0).toString());
                }
                catch (Exception ex) {
                }

                btnRemoveAdmin.setEnabled(aid > 0);
            }
        });

        tblAdmin.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    if (tblAdmin.getSelectedRow() >= 0) {
                        try {
                            int aid = Integer.parseInt(am.getValueAt(tblAdmin.getSelectedRow(), 0).toString());
                            ResultSet rs = DB.execQuery("SELECT * FROM Admins WHERE ID=" + aid);
                            if (rs.next()) {
                                AdminModel m = new AdminModel(rs.getInt("ID"), rs.getString("Username"), rs.getString("Password"));
                                App.getAdminUserFrame().loadData(m);
                                App.setDisplay(App.getAdminUserFrame());
                            }
                        }
                        catch (SQLException ex) {
                            Logger.getLogger(Admin.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                    else {
                        Utils.Alert("Please select data first");
                    }
                }
            }
        });

        tblManager.getTableHeader().setReorderingAllowed(false);
        tblAdmin.getTableHeader().setReorderingAllowed(false);
    }
    
    public void reloadData() {
        pm = new PagingModel(header, new QuestionRecord());
        tblManager.setModel(pm);
        pm.fireTableDataChanged();
        btnPrevious.setEnabled(false);
        btnNext.setEnabled(pm.getPageCount() > 1);
    }

    public void reloadAdminData() {
        am = new PagingModel(userheader, new UserRecord());
        tblAdmin.setModel(am);
        am.fireTableDataChanged();
        btnPreviousAdmin.setEnabled(false);
        btnNextAdmin.setEnabled(am.getPageCount() > 1);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ReportPanel = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblManager = new javax.swing.JTable();
        btnNewQA = new javax.swing.JButton();
        btnRemove = new javax.swing.JButton();
        btnPrevious = new javax.swing.JButton();
        btnNext = new javax.swing.JButton();
        lbManagerPage = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblAdmin = new javax.swing.JTable();
        btnNewAdmin = new javax.swing.JButton();
        btnRemoveAdmin = new javax.swing.JButton();
        btnPreviousAdmin = new javax.swing.JButton();
        btnNextAdmin = new javax.swing.JButton();
        lbAdminPage = new javax.swing.JLabel();
        jPanelReport = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jClose = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jReport = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Admin control");

        jScrollPane1.setViewportView(tblManager);

        btnNewQA.setText("New Q & A");
        btnNewQA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNewQAActionPerformed(evt);
            }
        });

        btnRemove.setText("Remove");
        btnRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoveActionPerformed(evt);
            }
        });

        btnPrevious.setText("Previous");
        btnPrevious.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPreviousActionPerformed(evt);
            }
        });

        btnNext.setText("Next");
        btnNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNextActionPerformed(evt);
            }
        });

        lbManagerPage.setText("jLabel1");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btnNewQA)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnRemove, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(49, 49, 49)
                        .addComponent(btnPrevious)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnNext, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lbManagerPage)
                        .addGap(0, 82, Short.MAX_VALUE))
                    .addComponent(jScrollPane1))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 345, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnNewQA)
                    .addComponent(btnRemove)
                    .addComponent(btnPrevious)
                    .addComponent(btnNext)
                    .addComponent(lbManagerPage))
                .addContainerGap())
        );

        ReportPanel.addTab("Q & A Manager", jPanel1);

        jScrollPane2.setViewportView(tblAdmin);

        btnNewAdmin.setText("New Admin");
        btnNewAdmin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNewAdminActionPerformed(evt);
            }
        });

        btnRemoveAdmin.setText("Remove Admin");
        btnRemoveAdmin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoveAdminActionPerformed(evt);
            }
        });

        btnPreviousAdmin.setText("Previous");
        btnPreviousAdmin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPreviousAdminActionPerformed(evt);
            }
        });

        btnNextAdmin.setText("Next");
        btnNextAdmin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNextAdminActionPerformed(evt);
            }
        });

        lbAdminPage.setText("jLabel2");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btnNewAdmin, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnRemoveAdmin)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnPreviousAdmin)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnNextAdmin, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lbAdminPage)
                        .addGap(34, 34, 34))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 345, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnNewAdmin)
                    .addComponent(btnPreviousAdmin)
                    .addComponent(btnNextAdmin)
                    .addComponent(lbAdminPage)
                    .addComponent(btnRemoveAdmin, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        ReportPanel.addTab("Admin Manager", jPanel2);

        javax.swing.GroupLayout jPanelReportLayout = new javax.swing.GroupLayout(jPanelReport);
        jPanelReport.setLayout(jPanelReportLayout);
        jPanelReportLayout.setHorizontalGroup(
            jPanelReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 524, Short.MAX_VALUE)
        );
        jPanelReportLayout.setVerticalGroup(
            jPanelReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 408, Short.MAX_VALUE)
        );

        ReportPanel.addTab("Report", jPanelReport);

        jMenu1.setText("File");

        jClose.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0));
        jClose.setText("Close");
        jClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCloseActionPerformed(evt);
            }
        });
        jMenu1.add(jClose);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setText("New Question & Answer");
        jMenu2.add(jMenuItem2);

        jReport.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
        jReport.setText("View Report");
        jReport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jReportActionPerformed(evt);
            }
        });
        jMenu2.add(jReport);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(ReportPanel)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(ReportPanel)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnNewAdminActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewAdminActionPerformed
        App.getAdminUserFrame().setEditMode(false);
        App.setDisplay(App.getAdminUserFrame());
    }//GEN-LAST:event_btnNewAdminActionPerformed

    private void jCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCloseActionPerformed
        App.switchDisplay(App.getMainFrame());
        this.dispose();
    }//GEN-LAST:event_jCloseActionPerformed

    private void jReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jReportActionPerformed
        App.setDisplay(App.getReportFrame());
    }//GEN-LAST:event_jReportActionPerformed

    private void btnNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNextActionPerformed
        PagingModel model = (PagingModel) tblManager.getModel();
        Component upButton = jScrollPane1.getCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER);
        Component downButton = jScrollPane1.getCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER);
        model.pageDown();

        // If we hit the bottom of the data, disable the down button.
        if (model.getPageOffset() == (model.getPageCount() - 1)) {
            btnNext.setEnabled(false);
            try {
                downButton.setEnabled(false);
            }
            catch (Exception ex) {
            }
        }
        try {
            upButton.setEnabled(true);
        }
        catch (Exception ex) {
        }
        btnPrevious.setEnabled(true);
        btnRemove.setEnabled(false);
        lbManagerPage.setText("Page: " + (model.getPageOffset() + 1) + "/" + model.getPageCount());
    }//GEN-LAST:event_btnNextActionPerformed

    private void btnPreviousActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPreviousActionPerformed
        PagingModel model = (PagingModel) tblManager.getModel();
        Component upButton = jScrollPane1.getCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER);
        Component downButton = jScrollPane1.getCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER);
        model.pageUp();
        // If we hit the bottom of the data, disable the down button.
        if (model.getPageOffset() == (model.getPageCount() - 1)) {
            btnNext.setEnabled(false);
            try {
                upButton.setEnabled(false);
            }
            catch (Exception ex) {
            }
        }
        try {
            downButton.setEnabled(true);
        }
        catch (Exception ex) {
        }
        btnNext.setEnabled(true);
        btnRemove.setEnabled(false);
        lbManagerPage.setText("Page: " + (model.getPageOffset() + 1) + "/" + model.getPageCount());                                 
    }//GEN-LAST:event_btnPreviousActionPerformed

    private void btnRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveActionPerformed
        if (tblManager.getSelectedRows().length != 1) {
            Utils.Alert("Please select 1 question you want to delete");
            return;
        }
        int qid = 0;
        try {
            qid = Integer.parseInt(pm.getValueAt(tblManager.getSelectedRow(), 0).toString());
        }
        catch (Exception ex) {
        }

        if (qid == 0) {
            return;
        }
        if (Utils.Confirm("Areu you sure want to remove question ID: " + qid) == 0) {
            if (QuestionModel.removeQuestion(qid)) {
                Utils.Alert("Removed question successfully");
                this.reloadData();
            }
            else {
                Utils.Alert("Removed question fail, please try again");
            }
        }
    }//GEN-LAST:event_btnRemoveActionPerformed

    private void btnNewQAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewQAActionPerformed
        App.setDisplay(App.getAdminNewQA().setQAEditMode(false));
    }//GEN-LAST:event_btnNewQAActionPerformed

    private void btnNextAdminActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNextAdminActionPerformed
        PagingModel model = (PagingModel) tblAdmin.getModel();
        Component upButton = jScrollPane2.getCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER);
        Component downButton = jScrollPane2.getCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER);
        model.pageDown();

        // If we hit the bottom of the data, disable the down button.
        if (model.getPageOffset() == (model.getPageCount() - 1)) {
            btnNextAdmin.setEnabled(false);
            try {
                downButton.setEnabled(false);
            }
            catch (Exception ex) {
            }
        }
        try {
            upButton.setEnabled(true);
        }
        catch (Exception ex) {
        }
        btnPreviousAdmin.setEnabled(true);
        btnRemoveAdmin.setEnabled(false);
        lbAdminPage.setText("Page: " + (model.getPageOffset() + 1) + "/" + model.getPageCount());
    }                                            

    private void removeAdminbtnActionPerformed(java.awt.event.ActionEvent evt) {                                               
        //delete
    }//GEN-LAST:event_btnNextAdminActionPerformed

    private void btnPreviousAdminActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPreviousAdminActionPerformed
         PagingModel model = (PagingModel) tblAdmin.getModel();
        Component upButton = jScrollPane2.getCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER);
        Component downButton = jScrollPane2.getCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER);
        model.pageUp();
        // If we hit the bottom of the data, disable the down button.
        if (model.getPageOffset() == (model.getPageCount() - 1)) {
            btnPreviousAdmin.setEnabled(false);
            try {
                upButton.setEnabled(false);
            }
            catch (Exception ex) {
            }
        }
        try {
            downButton.setEnabled(true);
        }
        catch (Exception ex) {
        }
        btnNextAdmin.setEnabled(true);
        btnRemoveAdmin.setEnabled(false);
        lbAdminPage.setText("Page: " + (model.getPageOffset() + 1) + "/" + model.getPageCount());
    }//GEN-LAST:event_btnPreviousAdminActionPerformed

    private void btnRemoveAdminActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveAdminActionPerformed
        if (tblAdmin.getSelectedRows().length != 1) {
            Utils.Alert("Please select 1 admin you want to delete");
            return;
        }
        int qid = 0;
        try {
            qid = Integer.parseInt(am.getValueAt(tblAdmin.getSelectedRow(), 0).toString());
        }
        catch (Exception ex) {
        }

        if (qid == 0) {
            return;
        }
        if(qid == App.adminUserID){
            Utils.Alert("You can not remove yourself");
            return;
        }
        if (Utils.Confirm("Areu you sure want to remove Admin ID: " + qid) == 0) {
            if (AdminModel.removeAdmin(qid)) {
                Utils.Alert("Removed admin successfully");
                this.reloadAdminData();
            }
            else {
                Utils.Alert("Removed admin fail, please try again");
            }
        }
    }//GEN-LAST:event_btnRemoveAdminActionPerformed
    
    private void formWindowClosing(java.awt.event.WindowEvent evt) {                                   
        this.dispose();
        App.setLogout();
        App.switchDisplay(App.getMainFrame());
    }
    
    private void reportPanelStateChanged(javax.swing.event.ChangeEvent evt) {                                         
        if (ReportPanel.getSelectedComponent().getName().equals("jPanelReport")) {
            ReportPanel.setSelectedIndex(0);
            jReport.doClick();
        }
    }          
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Admin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Admin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Admin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Admin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Admin().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTabbedPane ReportPanel;
    private javax.swing.JButton btnNewAdmin;
    private javax.swing.JButton btnNewQA;
    private javax.swing.JButton btnNext;
    private javax.swing.JButton btnNextAdmin;
    private javax.swing.JButton btnPrevious;
    private javax.swing.JButton btnPreviousAdmin;
    private javax.swing.JButton btnRemove;
    private javax.swing.JButton btnRemoveAdmin;
    private javax.swing.JMenuItem jClose;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanelReport;
    private javax.swing.JMenuItem jReport;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lbAdminPage;
    private javax.swing.JLabel lbManagerPage;
    private javax.swing.JTable tblAdmin;
    private javax.swing.JTable tblManager;
    // End of variables declaration//GEN-END:variables
}
